package com.order.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.order.admin.bean.Class;
import com.order.admin.bean.Data;
import com.order.admin.bean.Menu;
import com.order.admin.commonResponse.ComResponse;
import com.order.admin.mapper.MenuMapper;
import com.order.admin.service.ClassService;
import com.order.admin.service.impl.ClassServiceimpl;
import com.order.admin.service.impl.MenuServiceimpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class menuController {
    @Autowired
    MenuServiceimpl menuServiceimpl;

    @Autowired
    MenuMapper menuMapper;

    @Autowired
    ClassServiceimpl classServiceimpl;

    @Autowired
    ClassService classService;

    @ResponseBody
    @GetMapping("/menu")
    public ComResponse getAllMenu(){
        ComResponse<List<Menu>> objectComResponse = new ComResponse<>();
        List<Menu> menuList = menuServiceimpl.list();
        System.out.println(menuList);
        objectComResponse.setData(menuList);
        objectComResponse.setMsg("返回成功");
        return objectComResponse;
    }

    @ResponseBody
    @GetMapping("/class")
    public ComResponse getAllClass(){
        ComResponse<List<Class>> objectComResponse = new ComResponse<>();
        List<Class> classList = classServiceimpl.list();
        objectComResponse.setData(classList);
        objectComResponse.setMsg("返回成功");
        return objectComResponse;
    }

    @ResponseBody
    @GetMapping("/getMenuByClass")
    public ComResponse getMenuByClass(@RequestParam("class_id") String class_id){
        QueryWrapper<Menu> queryWrapper = new QueryWrapper<Menu>();
        queryWrapper.eq("class_id",class_id);
        ComResponse<List<Menu>> objectComResponse = new ComResponse<>();
        List<Menu> menuList = menuMapper.selectList(queryWrapper);
        objectComResponse.setData(menuList);
        objectComResponse.setMsg("返回成功");
        return objectComResponse;
    }

    @ResponseBody
    @PostMapping("/addMenu")
    public void add(@RequestBody Data data){
        menuServiceimpl.save(data.getBody());
    }
}
